/*

License:

    PDF UPLOAD METADATA EXTRACTOR for SharePoint 2010
    Copyright (C) 2012  Ingo Karstein

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

See my blog:
    http://blog.karstein-consulting.com
    
This project uses the iTextSharp v4.1.6 library that is licensed under LGPL and is published here:
    
    http://nuget.org/packages/iTextSharp-LGPL
    
    In Visual Studio 2012 just install iTextSharp v4.1.6 with NuGet. Open the "Package Manager Console"
    and type in "Install-Package iTextSharp-LGPL"
    
    http://itextsharp.svn.sourceforge.net/viewvc/itextsharp/tags/iTextSharp_4_1_6/

*/

using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using System.Diagnostics;
using iTextSharp.text;
using System.Collections.Generic;

namespace ik.SharePoint2010.PDFUploadMetadataExtractor.Features.Feature1
{
    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>

    [Guid("34362cf3-66d3-4561-8424-c6c1ada7d852")]
    public class Feature1EventReceiver : SPFeatureReceiver
    {
        // Uncomment the method below to handle the event raised after a feature has been activated.


        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;
            if( web != null )
            {
                List<Guid> listguid = new List<Guid>();

                foreach( SPList list in web.Lists )
                {
                    if( list.BaseType == SPBaseType.DocumentLibrary && list.Hidden == false )
                        listguid.Add(list.ID);
                }

                foreach( var g in listguid )
                {
                    ListEventReceiver.AddListItemEventReceiver(web.Lists[g], SPEventReceiverType.ItemAdded);
                }
            }
        }


        // Uncomment the method below to handle the event raised before a feature is deactivated.

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;
            if( web != null )
            {
                List<Guid> listguid = new List<Guid>();

                foreach( SPList list in web.Lists )
                {
                    if( list.BaseType == SPBaseType.DocumentLibrary )
                        listguid.Add(list.ID);
                }

                foreach( var g in listguid )
                {
                    ListEventReceiver.RemoveList(web.Lists[g]);
                }
            }
        }


        // Uncomment the method below to handle the event raised after a feature has been installed.

        //public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised before a feature is uninstalled.

        //public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        //{
        //}

        // Uncomment the method below to handle the event raised when a feature is upgrading.

        //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
        //{
        //}
    }
}
